<template>
  <div class="myContainer">
    <el-row class="myTitleBorderBottom">
      <el-col :span="12" class="myLineHeight_40px">{{this.title}}</el-col>
      <el-col :span="12" class="myTextAlignRight">      
        <!--<el-button type="primary" class="myBgGreen">数据同步</el-button>-->
      </el-col>    
    </el-row>
    <el-row class="myMarginTop_10px" :gutter="10">     
    	  <el-col :span="3">
        <template>
          <el-select 
            v-model="deleteStatus"
            clearable
            placeholder="全部设备类型">
            <el-option
              v-for="item in deleteStatusList"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
        </template>
      </el-col>
        <el-col :span="3">
        <template>
          <el-select 
            v-model="deleteStatus1"
            clearable
            placeholder="全部联网状态">
            <el-option
              v-for="item in deleteStatusList1"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
        </template>
      </el-col>
      <el-col :span="5">
        <el-input placeholder="请输入关键词" v-model="kw"></el-input>
      </el-col>
      <el-col :span="3">
        <el-button type="primary" class="myBgGreen" @click="fuzzySearch">查 询</el-button>
      </el-col>
    </el-row>
    <el-row class="myMarginTop_10px">
      <el-col :span="24">
        <el-table
          ref="multipleTable"
          :data="list"
          :border = true
          :stripe = true
          style="width: 100%"
          @selection-change="handleSelectionChange">
          <el-table-column
            type="selection"
            prop=""
             label="序号"
            width="55">
          </el-table-column>
          <el-table-column
            prop="area_name"
            label="所属区域"
            >
          </el-table-column>
          <el-table-column
            prop="device_name"
            label="设备名称"
            >             
          </el-table-column>
          <el-table-column
            prop="device_sn"
            label="设备SN号"
            >           
          </el-table-column>
          <el-table-column
            prop="device_type_name"
            label="设备类型"
            >                    
          </el-table-column>
          
            <el-table-column
            prop="device_version_code"
            label="设备版本名称"
            >            
          </el-table-column>          
            <el-table-column           
            label="联网状态"
            >  
            <template scope="scope">
              <span class="myColorRed" v-if="scope.row.connect_status==2">未连接</span>
              <span v-else>已连接</span>
            </template>
          </el-table-column>
        
            <el-table-column
            prop="upgrade_progress"
            label="升级状态"
            >  
             <template scope="scope">
              <span>{{scope.row.upgrade_progress | upgradeProgressType}}</span>
            </template>
          </el-table-column>         
          <el-table-column
            label="操作"
            width="100">
            <template scope="scope">
            	<el-button @click="getDetail(scope.row.device_id)" class="look" type="text" size="small">查看</el-button>                                        
            </template>
          </el-table-column>
        </el-table>
        <div class="block">                    
          <el-pagination
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="page_num"
            :page-sizes="[10, 15]"
            :page-size="page_size"
            layout="total, sizes, prev, pager, next, jumper"
            :total="total">
          </el-pagination>
        </div>
      </el-col>
    </el-row>
  </div>
</template>

<style scoped>
  .myContainer{
    background: #fff;
    padding: 10px;
  }
  .myTitleBorderBottom{
    color: #000;
    font-weight: 500;
    font-size: 16px;
    border-bottom: 1px solid #dbdbdb;
  }
  .myBgGreen{
    background: #00c2a9;
    border-color: #00c2a9;
    color: #fff;
    margin-top:2px;
  }
  .myBgGreen:hover{
    background: #33ceba;
  }
  .myTextAlignRight{
    text-align: right;
  }
  .myLineHeight_40px{
    line-height: 40px;
  }
  .myMarginTop_10px{
    margin-top: 10px;
  }
   .myColorRed{
    color: #f00;
  }
</style>

<script>
  import { getFaceList } from '@/api/entrance_guard';
  
  export default {
    data(){
      return{  
        title:"人脸识别设备管理",    
        list:[],  

        page_size: null, //每页显示多少条
        page_num: null, //当前页码
        total:null, //总条数  

        selectedLd:"-1",
        ldList:[],
        building_id:-1,
        lookObj:{},
      
        id:null,
        index:null,
        idArr:[],
        area_id: -1,
        pages:1000,
        loading:false,
        multipleSelection: [],
      
        kw:"",
        deleteStatus:"",
        deleteStatusList:[{value:1001,label:"单屏"},{value:2001,label:"闸机"},{value:3001,label:"桌面双屏"},{value:4001,label:"门禁"},{value:5001,label:"摄像头"}],
        deleteStatus1:"",
        deleteStatusList1:[{value:1,label:"联网"},{value:2,label:"断网"}],
      }
    },
    
    created() { 
    	document.title=this.title;
        this.fetchList();
    },

    

    filters: {
       upgradeProgressType: function(value) {
        let src = '';
        switch (value) {
          case 0:
            src = '可升级';
          break;
          case 1:
            src = '正在下载';
          break;
          case 2:
            src = '升级';
          break;
          case 3:
            src = '升级等待';
          break;
          case 4:
            src = '正在升级';
          break;
          case 5:
            src = '暂停升级';
          break;
        }
        return src;    
      }           
  },
 
    methods:{
       fetchList() {
        let vm = this;
        const params = {
          page_size: this.page_size,
          kw: this.kw,
          device_type_id:this.deleteStatus,
          connect_status:this.deleteStatus1,
          page_num: this.page_num
        }
        vm.loading = true;
        getFaceList(params)
        .then(response => {
          let res = response.data;
          vm.list = res.rows;
          vm.total = res.total;  
          vm.page_num = res.page_num;
          vm.page_size = res.page_size;
          
          vm.loading = false;
        })
        .catch(error => {
          vm.loading = false;
        });
      },
     
      fuzzySearch() {
         this.fetchList();
      },
      
      handleSizeChange(val) {
        this.page_size = val;
        this.fetchList();
      },
      
      handleCurrentChange(val) {
       let pageNum=window.localStorage.getItem("pageNum");
        if(pageNum){
          this.page_num = Number(pageNum);
          window.localStorage.removeItem("pageNum");
        }else{
          this.page_num = val;
        }
        this.fetchList();
      },
           
      getDetail:function(val){
       this.$router.push({
         path:'/faceManageComonents',
         query: {type: 'info', id: val, pageNum: this.page_num}
       })
     },
     
     //----页码---
      handleSelectionChange(val) {
        this.multipleSelection = val;
        if(val.length!=0){
          for(var i = 0;i<val.length;i++){
            this.idArr.push(val[i].area_id)
          }
        }else{
          this.idArr = [];
        }             
      },
       indexMethod(index) {
          return (this.page_num-1)*this.page_size + index + 1
      }
     
    }

  }


</script>



